#delimit ;
clear;
use pool_8090.dta;

/* run "data_creation.do" first */ ; 

#delimit ; 

gen lavginc_adj = ln(avginc); 
replace lavginc_adj =ln(avginc*1.25) if selfemp == 1;

/* Estimate Base Results */ ;

#delimit ;

ivreg lnw  age1 agesq  married female white child edudummy2-edudummy6 unempdummy2 unempdummy3 unempdummy4 yeardummy lumps
(permvar tranvar lavginc = occupdummy2-occupdummy8 occupage2-occupagesq8 inddummy2-inddummy12
 ctyunemp3 varctyunemp uniondummy1), robust;

gen ln_nw_hat = _b[permvar]*permvar + _b[tranvar]*tranvar + _b[lavginc]*lavginc   + _b[age1]*age1+_b[agesq]*agesq+
_b[married]*married +_b[female]*female + _b[white]*white + _b[child]*child +_b[yeardummy]*yeardummy + _b[lumps]*lumps +
   _b[edudummy2]*edudummy2 +_b[edudummy3]*edudummy3 +_b[edudummy4]*edudummy4 +_b[edudummy5]*edudummy5 
 +_b[edudummy6]*edudummy6 + _b[unempdummy2]*unempdummy2 + _b[unempdummy3]*unempdummy3 + _b[unempdummy4]*unempdummy4 
  + _b[_cons] ;

gen ln_nw_hat_1 = _b[lavginc]*lavginc   + _b[age1]*age1+_b[agesq]*agesq+_b[married]*married +
_b[female]*female + _b[white]*white + _b[child]*child +_b[yeardummy]*yeardummy + _b[lumps]*lumps +
   _b[edudummy2]*edudummy2 +_b[edudummy3]*edudummy3 +_b[edudummy4]*edudummy4 +_b[edudummy5]*edudummy5 
 +_b[edudummy6]*edudummy6 + _b[unempdummy2]*unempdummy2 + _b[unempdummy3]*unempdummy3 + _b[unempdummy4]*unempdummy4 
  + _b[_cons] ;

egen mean_ln_nw_hat = mean(ln_nw_hat);
egen mean_ln_nw_hat_1 = mean(ln_nw_hat_1);

gen nw_hat = exp(mean_ln_nw_hat);
gen nw_hat_1 = exp(mean_ln_nw_hat_1);

gen ratio = 1 - (nw_hat_1/nw_hat);

sum  ratio ;

drop ln_nw_hat ln_nw_hat_1 mean_ln_nw_hat mean_ln_nw_hat_1 nw_hat nw_hat_1 ratio ;


/* Estimate Results with Adjusted Income of the Self Employed */ ; 

#delimit ; 

ivreg lnw  age1 agesq  married female white child edudummy2-edudummy6 unempdummy2 unempdummy3 unempdummy4 yeardummy lumps
(permvar tranvar lavginc_adj = occupdummy2-occupdummy8 occupage2-occupagesq8 inddummy2-inddummy12
 ctyunemp3 varctyunemp uniondummy1), robust;

gen ln_nw_hat = _b[permvar]*permvar + _b[tranvar]*tranvar + _b[lavginc]*lavginc_adj   + _b[age1]*age1+_b[agesq]*agesq+
_b[married]*married +_b[female]*female + _b[white]*white + _b[child]*child +_b[yeardummy]*yeardummy + _b[lumps]*lumps +
   _b[edudummy2]*edudummy2 +_b[edudummy3]*edudummy3 +_b[edudummy4]*edudummy4 +_b[edudummy5]*edudummy5 
 +_b[edudummy6]*edudummy6 + _b[unempdummy2]*unempdummy2 + _b[unempdummy3]*unempdummy3 + _b[unempdummy4]*unempdummy4 
  + _b[_cons] ;

gen ln_nw_hat_1 = _b[lavginc]*lavginc_adj   + _b[age1]*age1+_b[agesq]*agesq+_b[married]*married +
_b[female]*female + _b[white]*white + _b[child]*child +_b[yeardummy]*yeardummy + _b[lumps]*lumps +
   _b[edudummy2]*edudummy2 +_b[edudummy3]*edudummy3 +_b[edudummy4]*edudummy4 +_b[edudummy5]*edudummy5 
 +_b[edudummy6]*edudummy6 + _b[unempdummy2]*unempdummy2 + _b[unempdummy3]*unempdummy3 + _b[unempdummy4]*unempdummy4 
  + _b[_cons] ;

egen mean_ln_nw_hat = mean(ln_nw_hat);
egen mean_ln_nw_hat_1 = mean(ln_nw_hat_1);

gen nw_hat = exp(mean_ln_nw_hat);
gen nw_hat_1 = exp(mean_ln_nw_hat_1);

gen ratio = 1 - (nw_hat_1/nw_hat);

sum  ratio ;

#delimit ;
drop ln_nw_hat ln_nw_hat_1 mean_ln_nw_hat mean_ln_nw_hat_1 nw_hat nw_hat_1 ratio;



